
export default {
  /**
   * 时间格式化 YYYY/MM/DD hh:mm:ss
   * @param date 时间对象
   */
	
	/*
	respondent_realm  内容类型：
	ARTICLE-资讯；
	HEADLINE-早报；
	LIVE-直播；
	CARD-名片;
	LEARN-课程;
	OWNER_CONTENT-转发助手	
	POSTER  -海报
	
	type   操作类型：
	VIEW-访问；
	DOWNLOAD-下载；
	SHARE-分享到微信；
	SHARE_CHAT-分享到好友聊天；
	SHARE_MOMENTS-分享到朋友圈
	*/
	getRespondentRealmName(type){
		//   财经早报    精品海报   智能名片  财经资讯   精选课程  
		if(type == 'ARTICLE'){
			return '财经资讯'
		}else if(type == 'HEADLINE'){
			return '财经早报'
		}else if(type == 'LIVE'){
			return '直播'
		}else if(type == 'CARD'){
			return '智能名片'
		}else if(type == 'LEARN'){
			return '精选课程 '
		}else if(type == 'OWNER_CONTENT'){
			return '转发助手'
		}else if(type == 'POSTER'){
			return '精品海报'
		}	
	},
	getShareTypeName(type){
		if(type == 'SHARE_CHAT'){
			return '微信好友'
		}else if(type == 'SHARE_MOMENTS'){
			return '微信朋友圈'
		}else if(type == 'SHARE'){
			return '微信'
		}	
	},
	
	getChineseDay(){
		let day = new Date().getDay()								
		let dayArr = ['星期一','星期二','星期三','星期四','星期五','星期六','星期日']		
		return dayArr[day-1]		
	},
	getChineseDate(){
		let month = new Date().getMonth() + 1								
		let date = new Date().getDate()	
		
		return `${month}/${date}`		
	},
	
  formatTime(date) {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()

    return [year, month, day].map(this.formatNumber).join('/') + ' ' + [hour, minute, second].map(this.formatNumber).join(':')
  },
	
	formatTime1(date) {
	  const year = date.getFullYear()
	  const month = date.getMonth() + 1
	  const day = date.getDate()
	  const hour = date.getHours()
	  const minute = date.getMinutes()
	  const second = date.getSeconds()
	
	  return [year, month, day].map(this.formatNumber).join('/')
	},
	
  formatNumber(n) {
    n = n.toString()
    return n[1] ? n : '0' + n
  },
  //中文姓名校验
  checkName(str) {
    const rule = /^[\u4e00-\u9fa5]+$/
    if (rule.test(str)) {
      return true
    } else {
      return false
    }
  },
  //手机号码校验
  checkPhone(str) {
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
    if (!myreg.test(str)) {
      return false;
    } else {
      return true;
    }
  },
  //身份证号码校验
  checkIdcard(str) {
    const rule = /^((1[1-5])|(2[1-3])|(3[1-7])|(4[1-6])|(5[0-4])|(6[1-5])|71|(8[12])|91)\d{4}(((((19|20)((\d{2}(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(\d{2}(0[13578]|1[02])31)|(\d{2}02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[48])0229)))|20000229)\d{3}(\d|X|x))|(((\d{2}(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(\d{2}(0[13578]|1[02])31)|(\d{2}02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[48])0229))\d{3}))$/ //身份证号
    if (rule.test(str)) {
      return true
    } else {
      return false
    }
  },
  // 数字输入检查
  checkNumber(num) {
    var str = num;
    var len1 = str.substr(0, 1);
    var len2 = str.substr(1, 1);
    //如果第一位是0，第二位不是点，就用数字把点替换掉
    if (str.length > 1 && len1 == 0 && len2 != ".") {
      str = str.substr(1, 1);
    }
    //第一位不能是.
    if (len1 == ".") {
      str = "";
    }
    //限制只能输入一个小数点
    if (str.indexOf(".") != -1) {
      var str_ = str.substr(str.indexOf(".") + 1);
      if (str_.indexOf(".") != -1) {
        str = str.substr(0, str.indexOf(".") + str_.indexOf(".") + 1);
      }
    }
    var a = str.indexOf(".");
    if (a != -1) {
      var b = str.substr(a + 1);
      if (b.length > 2) {
        str = str.substr(0, str.length - 1)
      }
      if (b == "00") {
        str = Math.floor(str)
      }
    }
    if (str === 0 || !str) {
      str = ''
    }
    //正则替换，保留数字和小数点
    // str = str.replace(/[^\d^\.]+/g, "");
    //如果需要保留小数点后两位，则用下面公式
    return str
  },
  //判断是否为微信内置浏览器
  checkWechatBrowser(){
    let ua = window.navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i) == 'micromessenger'){
      return true;
    }else{
      return false;
    }
  },
  //设置头部标题
  setDocumentTitle(title){
    document.title=title
  },
  //根据日期计算星期几
  getWeekDay(date){
    let time=date.substr(0,10)
    let dt = new Date(time.split("/")[0], time.split("/")[1]-1,time = time.split("/")[2]);
    let weekDay = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    return weekDay[dt.getDay()];
  }
}


export function Appendzero(obj)
{
		if(obj<10) return "0" +""+ obj;
		else return obj;
}
export function getWeek(weeknum)
{
		let week = ''
		if(weeknum==0) {return  week="周日";} 
		else if(weeknum==1) {return  week="周一";} 
		else if(weeknum==2) {return  week="周二";} 
		else if(weeknum==3) {return  week="周三";}
		else if(weeknum==4) {return  week="周四";}
		else if(weeknum==5) {return  week="周五";}
		else if(weeknum==6) {return  week="周六";}
		return week;
}
